runsc: add --restrict-bind-to-loopback flag#13611
Open
sfc-gh-mkeralapura wants to merge 1 commit into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
177ec9e to
3b5a22a
Compare
When enabled, bind(2) returns EACCES for any address that is not a loopback address, including INADDR_ANY (0.0.0.0) and IN6ADDR_ANY (::). Loopback classification is delegated to net.IP.IsLoopback() from the Go standard library. AF_UNIX and other address families are unaffected. Thread safety: RestrictBindToLoopback is written once during sandbox boot (loader.go:New) before any task goroutines are created, and is read-only thereafter — the same pattern used by AllowSUID and IOUringEnabled. The flag is only meaningful with sandbox networking (--network=sandbox). With host networking the sentry syscall handlers are not invoked for socket calls, so the check is a no-op. Tests: - runsc/config: TestRestrictBindToLoopback verifies flag round-trips through RegisterFlags/NewFromFlags/ToFlags. - test/syscalls/linux/restrict_bind_loopback_test: eight cases covering IPv4 INADDR_ANY (rejected), non-loopback unicast (rejected), 127.0.0.1 / 127.x.x.x (allowed), IPv6 IN6ADDR_ANY (rejected), ::1 (allowed), ::ffff:127.0.0.1 (allowed), and ::ffff:0.0.0.0 (rejected). Tests skip automatically when the flag is not active, so they are safe to run on plain Linux or gVisor without the flag. Assisted-by: Claude Sonnet 4.6
3b5a22a to
3d4d9e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sandboxed workloads often have no legitimate reason to accept connections on external network interfaces, yet nothing prevents them from calling bind(2) with INADDR_ANY. This flag enforces the principle of least privilege at the kernel level: a process that should only be reachable on loopback cannot accidentally expose itself on a routable interface, even if it attempts to.
It is particularly useful in environments where a sidecar proxy (rather than the application itself) owns the external-facing port and the application should be invisible outside the sandbox.
When enabled, bind(2) returns EACCES for any address that is not a loopback address, including INADDR_ANY (0.0.0.0) and IN6ADDR_ANY (::). Loopback classification is delegated to net.IP.IsLoopback() from the Go standard library. AF_UNIX and other address families are unaffected.
Thread safety: RestrictBindToLoopback is written once during sandbox boot (loader.go:New) before any task goroutines are created, and is read-only thereafter — the same pattern used by AllowSUID and IOUringEnabled.
The flag is only meaningful with sandbox networking (--network=sandbox). With host networking the sentry syscall handlers are not invoked for socket calls, so the check is a no-op.
Tests:
through RegisterFlags/NewFromFlags/ToFlags.
IPv4 INADDR_ANY (rejected), non-loopback unicast (rejected),
127.0.0.1 / 127.x.x.x (allowed), IPv6 IN6ADDR_ANY (rejected), ::1
(allowed), ::ffff:127.0.0.1 (allowed), and ::ffff:0.0.0.0 (rejected).
Tests skip automatically when the flag is not active, so they are safe
to run on plain Linux or gVisor without the flag.
Assisted-by: Claude Sonnet 4.6